home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / DRIVERS.ACC / DEVICE.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  14.5 KB  |  662 lines

  1. /* ===================================================================
  2.  * FILE: DEVICE.C
  3.  * ===================================================================
  4.  * DATE: November 20, 1992
  5.  *     
  6.  * 
  7.  * DESCRIPTION: DRIVERS ACC
  8.  *
  9.  * This file handles the front end dialog box.
  10.  *
  11.  * COMPILER: TURBO C Version 2.0
  12.  */
  13.  
  14.  
  15. /* INCLUDE FILES
  16.  * ===================================================================
  17.  */
  18. #include <sys\gemskel.h>
  19. #include <tos.h>
  20. #include <linea.h>
  21. #include <string.h>
  22.  
  23. #include "country.h"
  24. #include "drvhead.h"
  25. #include "drivers.h"
  26. #include "fixrsh.h"
  27. #include "mainstuf.h"
  28. #include "xform_do.h"
  29. #include "windows.h"
  30. #include "text.h"
  31. #include "fsmio.h"
  32. #include "mover.h"
  33. #include "options.h"
  34. #include "custom.h"
  35. #include "path.h"
  36.  
  37.  
  38. /* STRUCTURES
  39.  * ===================================================================
  40.  */
  41. struct foobar {
  42.     WORD    dummy;
  43.     WORD    *image;
  44.     };
  45.  
  46. typedef struct jar_entry
  47. {
  48.   long    cookie;
  49.   long    value;
  50. }JAR_ENTRY;
  51.  
  52.  
  53. struct _INFO
  54. {
  55.      long  dummy1;
  56.      int   dummy2;
  57.      int   quality;
  58. }*info;
  59.  
  60.  
  61.  
  62.  
  63. /* EXTERN
  64.  * ===================================================================
  65.  */
  66. extern int AES_Version;
  67.  
  68.  
  69.  
  70. /* PROTOTYPES
  71.  * ===================================================================
  72.  */
  73. void     initialize( void );
  74. int     handle_front( int button, WORD *msg );
  75. int     handle_button( int button, WORD *msg );
  76.  
  77. void     Reset_Tree( OBJECT *tree );
  78. int     open_vwork( void );
  79. void     close_vwork( void );
  80.  
  81. void     MF_Save( void );
  82. void     MF_Restore( void );
  83. void     Scan_Message( OBJECT *Tree, BOOLEAN flag );
  84. void     RestoreMainTree( void );
  85.  
  86. void     ClearChangeFlag( void );
  87. void     SetChangeFlag( void );
  88. BOOLEAN     IsChangeFlag( void );
  89.  
  90. void     CloseWindow( void );
  91. void     InitDriverNames( void );
  92. long     get_cookie( void );
  93. void     ChangeButton( OBJECT *tree, int obj, int flag );
  94.  
  95. void     SetDevices( void );
  96.  
  97.  
  98.  
  99. /* DEFINES
  100.  * ===================================================================
  101.  */
  102. #define MENU_WIDTH  27
  103. #define UNDO    0x6100
  104. #define p_cookies   (*(JAR_ENTRY **)0x5a0)
  105. #define COOKIE        0x46534d43L    /* FSMC */
  106.  
  107.  
  108.  
  109. /* GLOBALS
  110.  * ===================================================================
  111.  */
  112. int     Item;            /* Index of which item was selected from the menu */
  113. BOOLEAN ChangeFlag;    /* TRUE - Parameter has changed in the ASSIGN.SYS */
  114. char    driver_text[30];/* Text to display driver name                    */
  115. BOOLEAN cookie_flag;    /* TRUE - FSMC COOKIE EXISTS */
  116. int    old_quality;
  117.  
  118.  
  119. /* FUNCTIONS
  120.  * ===================================================================
  121.  */
  122.  
  123.  
  124. /* initialize()
  125.  *==========================================================================
  126.  * Initialize the variables and sliders before displaying the resource.
  127.  */
  128. void
  129. initialize( void )
  130. {
  131.      Wind_get( 0, WF_WORKXYWH, ( WARGS *)&desk );
  132.      fsel_init();
  133.      linea_init();
  134.  
  135.      MF_Save();
  136.      Scan_Message( ad_scan, TRUE );    
  137.      get_bitpath();
  138.      read_fonts();
  139.      DeleteAssignOld();
  140.      
  141.      Scan_Message( ad_scan, FALSE );
  142.      MF_Restore();
  143.  
  144.      /* Initialize the Quality Section */     
  145.      Disable( FQUALITY );
  146.      Disable( FDRAFT );
  147.      Disable( FFINAL );
  148.  
  149.      Deselect( FDRAFT );
  150.      Deselect( FFINAL );
  151.  
  152.      NoTouchExit( FDRAFT );
  153.      NoTouchExit( FFINAL );
  154.      
  155.      if( cookie_flag )
  156.      {
  157.         Enable( FQUALITY );
  158.         Enable( FDRAFT );
  159.         Enable( FFINAL );
  160.      
  161.         MakeTouchExit( FDRAFT );
  162.         MakeTouchExit( FFINAL );
  163.            
  164.         if( info->quality )
  165.         {
  166.            old_quality = TRUE;
  167.            Select( FFINAL );
  168.         }   
  169.         else
  170.         {
  171.            old_quality = FALSE;
  172.            Select( FDRAFT );
  173.         }   
  174.      }
  175.  
  176.      SetDevices();     
  177.      ClearChangeFlag();
  178. }
  179.  
  180.  
  181.  
  182. /* SetDevices()
  183.  * ====================================================================
  184.  */
  185. void
  186. SetDevices( void )
  187. {
  188.      current_device = device_head;
  189.      InitDriverNames();
  190.  
  191.      mover_setup( hdriver_head, cdriver_count,
  192.           FBASE, FSLIDER, FUP, FDOWN,
  193.           LINE0, LINE7, LINEBASE, 0, 8 );
  194.  
  195.      MakeExit( FREMOVE );
  196.      Enable( FREMOVE );
  197.      MakeExit( FCONFIG );
  198.      Enable( FCONFIG );
  199.      
  200.      /* If there is no active printer, disable remove and configure */
  201.      if( cur_cdriver == -1 )
  202.      {
  203.         NoExit( FCONFIG );
  204.     Disable( FCONFIG );     
  205.     
  206.     NoExit( FREMOVE );
  207.     Disable( FREMOVE );
  208.      }
  209.      
  210.      
  211.      /* If this is NOT a FSM_GDOS/SPEEDO driver, disable configure */
  212.      if( cur_cdriver != -1 )
  213.      {
  214.         if( strstr( cdrivers[ cur_cdriver ], NonSpeedo ) )
  215.         {
  216.            NoExit( FCONFIG );
  217.            Disable( FCONFIG );
  218.         }
  219.      }
  220.  
  221. }
  222.  
  223.  
  224.  
  225. /* handle_front()
  226.  * ====================================================================
  227.  */
  228. int
  229. handle_front( int button, WORD *msg )
  230. {
  231.    int  quit;
  232.    int  dclick;
  233.    HDEVICE_PTR curptr;
  234.    DEV_PTR xcurptr;
  235.       
  236.    dclick = FALSE;   
  237.    quit   = FALSE;
  238.       
  239.    /* Handle Double-clicking of the objects */   
  240.    if( ( button != -1 ) && ( button & 0x8000 ) )
  241.    {
  242.       button &= 0x7FFF;      
  243.       dclick = TRUE;
  244.    }   
  245.    
  246.    switch( button )
  247.    {
  248.      case FSAVE:    /* OK */
  249.                  quit = TRUE;
  250.                  Deselect( FSAVE );
  251.                  CloseWindow();
  252.                  break;
  253.    
  254.      case FEXIT:    /* CANCEL!!!! - RESTORE ASSIGN.OLD IF POSSIBLE */
  255.                  quit = TRUE;
  256.                  Deselect( FEXIT );
  257.                  
  258.                  /* Restore ASSIGN.OLD to ASSIGN.SYS */
  259.                  RenameAssignOld();
  260.                  
  261.                  /* Restore the DRAFT/FINAL flag */
  262.                  if( cookie_flag )
  263.               info->quality = old_quality;
  264.               
  265.                  CloseWindow();
  266.                  break;
  267.  
  268.  
  269.      case FCONFIG:
  270.      case FPRINTER: if( cur_cdriver != -1 )
  271.                      DoDrivers( cur_cdriver );
  272.                  if( button == FCONFIG )    
  273.                     XDeselect( tree, FCONFIG );    
  274.                  break;
  275.                  
  276.      case LINE0:
  277.      case LINE1:
  278.      case LINE2:
  279.      case LINE3:
  280.      case LINE4:
  281.      case LINE5:
  282.      case LINE6:
  283.      case LINE7:                 
  284.      case FUP:
  285.      case FDOWN:
  286.      case FBASE:
  287.      case FSLIDER:  if( dclick )
  288.                  {
  289.                   curptr = Active_Slit[ button - First_Obj ];
  290.                   if( !curptr )
  291.                         return( quit );          
  292.                    DoDrivers( HNAME( curptr ) );
  293.                  }
  294.                  else
  295.                    mover_button( button );
  296.                  break;
  297.  
  298.      case FREMOVE:  xcurptr = find_device( 21 );
  299.                  if( xcurptr )
  300.                  {
  301.                 /* ASK if we want it removed first.*/
  302.                if( form_alert( 1, alert56 ) == 2 )
  303.                {
  304.                    XDeselect( tree, FREMOVE );
  305.                    return( quit );
  306.                }       
  307.                  
  308.                     SetChangeFlag();
  309.                     
  310.                     TedText( FPRINTER ) = &driver_null[0];     
  311.                Objc_draw( tree, FPRINTER, MAX_DEPTH, NULL );
  312.                Undo_Fnodes( hdriver_head );
  313.                     XDeselect( tree, FREMOVE );
  314.                     cur_cdriver = -1;
  315.                DeleteDevice( 21 );
  316.                     
  317.                     if( !IsDisabled( FCONFIG ) )
  318.                  ChangeButton( tree, FCONFIG, FALSE );
  319.                  
  320.                if( !IsDisabled( FREMOVE ) )
  321.                  ChangeButton( tree, FREMOVE, FALSE );  
  322.                  
  323.                /* WRITE ASSIGN.SYS IMMEDIATELY */  
  324.                write_assign();
  325.                  }   
  326.                  break;
  327.  
  328.      case FCUSTOM:  Deselect( FCUSTOM );
  329.                  DoCustom();
  330.                  break;
  331.                  
  332.      case FSETPATH: XDeselect( tree, FSETPATH );
  333.             DoFontPath();
  334.             break;
  335.  
  336.      case FDRAFT:  if( cookie_flag && !IsSelected( FDRAFT ) )
  337.                     {
  338.                        XSelect( tree, FDRAFT );
  339.                        XDeselect( tree, FFINAL );
  340.                        
  341.                        /* Set the DRAFT Quality */
  342.                     info->quality = 0;
  343.                     }
  344.                 break;
  345.      
  346.      case FFINAL:  if( cookie_flag && !IsSelected( FFINAL ) )
  347.                 {
  348.                    XSelect( tree, FFINAL );
  349.                    XDeselect( tree, FDRAFT );
  350.                    
  351.                    /* Set the FINAL QUALITY */
  352.               info->quality = 1;     
  353.                 }
  354.                 break;
  355.                 
  356.      default:     if( button == -1 )
  357.               {
  358.                 switch( msg[0] )
  359.                 {
  360.                   case WM_REDRAW: 
  361.                                break;
  362.                                    
  363.                   case AC_CLOSE:  quit = TRUE;
  364.                                break;
  365.                                        
  366.                   case WM_CLOSED: quit = TRUE;
  367.                                CloseWindow();
  368.                      break;
  369.  
  370.              case CT_KEY:
  371.                           break;
  372.                   default:
  373.                           break;
  374.                 }
  375.               }
  376.               break;
  377.    }
  378.    return( quit );
  379.  
  380. }
  381.  
  382.  
  383.  
  384.  
  385. /* Reset_Tree()
  386.  *==========================================================================
  387.  * Make the incoming tree the active tree setting the x,y coordinates
  388.  * at the same time.
  389.  */
  390. void
  391. Reset_Tree( OBJECT *xtree )
  392. {
  393.   int x,y;
  394.   
  395.   x = ObX( ROOT );
  396.   y = ObY( ROOT );
  397.   ActiveTree( xtree );
  398.   ObX( ROOT ) = x;
  399.   ObY( ROOT ) = y;
  400. }
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407. /* MF_Save()
  408.  *==========================================================================
  409.  * Save the current mouse image.
  410.  */
  411. void
  412. MF_Save( void )
  413. {
  414.    if( AES_Version >= 0x0320 )
  415.    {
  416.      graf_mouse( 258, 0L );
  417.      graf_mouse( BUSYBEE, 0L );
  418.    }
  419. }
  420.  
  421.  
  422.  
  423. /* MF_Restore()
  424.  *==========================================================================
  425.  * Restore the previously saved mouse image.
  426.  */
  427. void
  428. MF_Restore( void )
  429. {
  430.   if( AES_Version >= 0x0320 )
  431.     graf_mouse( 259, 0L );
  432. }
  433.  
  434.  
  435.  
  436.  
  437. /* open_vwork()
  438.  *==========================================================================
  439.  * Open the virtual workstation. ( Note that the workstation should
  440.  * be closed after doing whatever you have to do. )
  441.  * OUT: 0 - failed
  442.  *      non-zero = handle
  443.  *      vhandle == new handle tho...
  444.  */
  445. int
  446. open_vwork( void )
  447. {
  448.     int i;
  449.     
  450.     work_in[0] = Getrez() + 2;
  451.     for( i = 1; i < 10; work_in[i++] = 1 );
  452.     work_in[10] = 2;
  453.     vhandle = phys_handle;
  454.     v_opnvwk( work_in, &vhandle, work_out );
  455.     return( vhandle );
  456. }
  457.  
  458.  
  459.  
  460.  
  461. /* close_vwork()
  462.  *==========================================================================
  463.  * Close the virtual workstation.
  464.  */
  465. void
  466. close_vwork( void )
  467. {
  468.    if( vhandle )
  469.    {
  470.       v_clsvwk( vhandle );
  471.       vhandle = 0;
  472.    }
  473. }
  474.  
  475.  
  476. /* Open_Scanning()
  477.  *==========================================================================
  478.  * Displays the dialog box using 'Tree';
  479.  * IN: flag = TRUE  - Display the dialog box.
  480.  *          = FALSE - Generate the Redraw Message
  481.  */
  482. void
  483. Scan_Message( OBJECT *Tree, BOOLEAN flag )
  484. {  
  485.      static GRECT rect;
  486.      static GRECT xrect;
  487.      
  488.      if( flag )
  489.      {
  490.        xrect.g_x = xrect.g_y = 10;
  491.        xrect.g_w = xrect.g_h = 36;
  492.    
  493.        Form_center( Tree, &rect );
  494.        Form_dial( FMD_START, &xrect, &rect );
  495.        Objc_draw( Tree, ROOT, MAX_DEPTH, &rect );
  496.      }
  497.      else
  498.        Form_dial( FMD_FINISH, &xrect, &rect );
  499. }
  500.  
  501.  
  502.  
  503. /* RestoreMaintree()
  504.  * =======================================================================
  505.  * Return from a tree BACK to the previous tree
  506.  */
  507. void
  508. RestoreMainTree( void )
  509. {
  510.    Reset_Tree( PrevTree );     
  511.    Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  512. }
  513.  
  514.  
  515.  
  516. /************************************************************************
  517.  * SETTIN/CLEARING a flag to see if the assign.sys has changed
  518.  ************************************************************************
  519.  */
  520.  
  521. /* ClearChangeFlag()
  522.  * =======================================================================
  523.  * Clears the ChangeFlag variable.
  524.  */
  525. void
  526. ClearChangeFlag( void )
  527. {
  528.    ChangeFlag = FALSE;
  529. }
  530.  
  531.  
  532. /* SetChangeFlag()
  533.  * =======================================================================
  534.  * Sets the ChangeFlag variable signifying that the ASSIGN.SYS has changed.
  535.  */
  536. void
  537. SetChangeFlag( void )
  538. {
  539.   ChangeFlag = TRUE;
  540. }
  541.  
  542.  
  543. /* IsChangeFlag()
  544.  * =======================================================================
  545.  * Returns TRUE/FALSE if the ASSIGN.SYS has been changed. TRUE - YES.
  546.  */
  547. BOOLEAN
  548. IsChangeFlag( void )
  549. {
  550.    return( ChangeFlag );
  551. }
  552.  
  553. /* CloseWindow()
  554.  * =======================================================================
  555.  * The user has pressed the close window box. Check to see if any
  556.  * parameters have been changed. If so, prompt the user and save the
  557.  * ASSIGN.SYS if necessary.
  558.  */
  559. void
  560. CloseWindow( void )
  561. {
  562. #if 0
  563.    if( cookie_flag )
  564.    {
  565.       ActiveTree( ad_front );
  566.       info->quality = (( IsSelected( FDRAFT ) ) ? ( 0 ) : ( 1 ) );     
  567.    } 
  568. #endif   
  569. }
  570.  
  571.  
  572. /* InitDriverNames()
  573.  * =======================================================================
  574.  * Initializes the Driver Names in the Chooser Tree.
  575.  * The 'tree' must already be set by the calling routine.
  576.  */
  577. void
  578. InitDriverNames( void )
  579. {
  580.      DEV_PTR temp_device;
  581.      HDEVICE_PTR hptr;
  582.      int     num;
  583.           
  584.      temp_device = find_device( 21 );    /* find the printer device */
  585.  
  586.      TedText( FPRINTER ) = &driver_null[0];     
  587.      cur_cdriver = -1;
  588.      
  589.      if( temp_device )
  590.      {    /*Found a printer device! */
  591.     num = FindCDriverIndex( DNAME( temp_device ) );
  592.         if( num != -1 )
  593.         {
  594.           hptr = Find_HDevice( num );  /* SET it visually inversed */
  595.           if( hptr )
  596.              HFLAG( hptr ) = TRUE;
  597.              
  598.           cur_cdriver = num;  
  599.           strcpy( driver_text, cdrivers[ num ] ); /* Set Name to Show*/
  600.           TedText( FPRINTER ) = &driver_text[0];
  601.         }
  602.      }
  603. }
  604.  
  605.  
  606.  
  607. /* get_cookie()
  608.  * ====================================================================
  609.  */
  610. long
  611. get_cookie( void )
  612. {
  613.     JAR_ENTRY    *pjar;
  614.  
  615.     info = ( struct _INFO *)NULL;
  616.     pjar = p_cookies;
  617.     if( !pjar ) return( 0L );
  618.     while( pjar->cookie )
  619.     {
  620.     if( pjar->cookie == COOKIE )
  621.         info = (struct _INFO *)( pjar->value );
  622.     ++pjar;
  623.     }
  624.     cookie_flag = (( info ) ? ( TRUE ) : ( FALSE ));
  625.     return( 0L );
  626. }
  627.  
  628.  
  629.  
  630. /* ChangeButton()
  631.  * ====================================================================
  632.  */
  633. void
  634. ChangeButton( OBJECT *tree, int obj, int flag )
  635. {
  636.    GRECT rect;
  637.    
  638.    /* turn on/off the REMOVE button here too */
  639.    rect = ObRect( obj );
  640.    objc_offset( tree, obj, &rect.g_x, &rect.g_y );
  641.  
  642.    rect.g_x -= 5;
  643.    rect.g_y -= 5;
  644.    rect.g_w += 10;
  645.    rect.g_h += 10;
  646.  
  647.    if( flag )
  648.    {
  649.        MakeExit( obj );
  650.        Enable( obj );
  651.    }
  652.    else
  653.    {
  654.        NoExit( obj );
  655.        Disable( obj );           
  656.    }
  657.    Objc_draw( tree, ROOT, MAX_DEPTH, &rect );
  658. }
  659.  
  660.  
  661.  
  662.